const app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var user = require('../../services/user.js');
Page({
  data: {
    trainList: [],
    bannerList: [],
    channel: [
      { url: '/pages/wuyou/index/index', id: '1', icon_url: '../../static/images/icon_a.png', name: '培训无忧' },
      { url: '/pages/train/list/index?train_type_id=101', id: '2', icon_url: '../../static/images/icon_b.png', name: '名师课堂' },
      { url: '/pages/train/list/index?train_type_id=102', id: '3', icon_url: '../../static/images/icon_c.png', name: '学者工作坊' }, 
      { url: '/pages/train/list/index?train_type_id=103', id: '4', icon_url: '../../static/images/icon_d.png', name: '读书汇' }, 
      { url: '/pages/train/list/index?train_type_id=104', id: '5', icon_url: '../../static/images/icon_e.png', name: '夏令营' },
      { url: '/pages/qqgroup/list/index?train_type_id=116', id: '6', icon_url: '../../static/images/icon_f.png', name: '群主来了' },
      { url: '/pages/teacher/list/index?train_type_id=124', id: '7', icon_url: '../../static/images/icon_g.png', name: '我要咨询' },
      { url: '/pages/teacher/list/index?train_type_id=123', id: '8', icon_url: '../../static/images/icon_h.png', name: '培训专家' },
      { url: '/pages/institution/list/index', id: '9', icon_url: '../../static/images/icon_h.png', name: '机构信息' }
    ]
  },
  
  onLoad: function () {
    this.getIndexData();
    this.getTrainTypeList();
  },
  getTrainTypeList:function(){
    util.request(api.TrainTypeList).then(res => {
      if (res.code === 200) {
        wx.setStorageSync("trainType", res.data)
      }
    });
  },
  getIndexData: function () {
    let that = this;
    util.request(api.IndexUrl).then(res=>{
      if (res.code === 200) {
        that.setData({
          trainList: res.data.trainList,
          bannerList: res.data.bannerList
        });
      }
    }).catch(() => {
      // wx.navigateTo({
      //   url: '/pages/auth/login/login',
      // })
    });
  },
  onShareAppMessage: function () {
    return {
      title: '大众课堂',
      desc: '大众课堂',
      path: '/pages/index/index'
    }
  }
  
})
